package com.ruoyi.activiti.domain;

import com.ruoyi.activiti.service.Candidate;
import org.activiti.engine.impl.persistence.entity.TaskEntityImpl;
import org.activiti.engine.impl.persistence.entity.VariableInstanceEntity;
import org.activiti.engine.task.Task;

import java.util.*;

/**
 * @author danghf
 * @version 1.0
 * @date 2024/05/06 17:24
 * 任务类
 */
public class ITask implements Candidate {
    /**
     * 候选组
     */
    private List<Long> candidateGroupIds;
    private List<String> candidateGroupNames;

    /**
     * 候选人
     */
    private List<Long> candidateUserIds;
    private List<String> candidateUserNames;

    public List<Long> getCandidateGroupIds() {
        return candidateGroupIds;
    }

    public void setCandidateGroupIds(List<Long> candidateGroupIds) {
        this.candidateGroupIds = candidateGroupIds;
    }

    public List<String> getCandidateGroupNames() {
        return candidateGroupNames;
    }

    public void setCandidateGroupNames(List<String> candidateGroupNames) {
        this.candidateGroupNames = candidateGroupNames;
    }

    public List<Long> getCandidateUserIds() {
        return candidateUserIds;
    }

    public void setCandidateUserIds(List<Long> candidateUserIds) {
        this.candidateUserIds = candidateUserIds;
    }

    public List<String> getCandidateUserNames() {
        return candidateUserNames;
    }

    public void setCandidateUserNames(List<String> candidateUserNames) {
        this.candidateUserNames = candidateUserNames;
    }

    // 负责人名称
    private String assigneeName;

    public String getAssigneeName() {
        return assigneeName;
    }

    public void setAssigneeName(String assigneeName) {
        this.assigneeName = assigneeName;
    }

    // 流程名称
    private String processDefinitionName;
    // 流程版本
    private String processDefinitionVersion;

    public String getProcessDefinitionVersion() {
        return processDefinitionVersion;
    }

    public void setProcessDefinitionVersion(String processDefinitionVersion) {
        this.processDefinitionVersion = processDefinitionVersion;
    }

    public String getProcessDefinitionName() {
        return processDefinitionName;
    }

    public void setProcessDefinitionName(String processDefinitionName) {
        this.processDefinitionName = processDefinitionName;
    }

    private String startUserName;
    private Long startUserId;

    public String getStartUserName() {
        return startUserName;
    }

    public void setStartUserName(String startUserName) {
        this.startUserName = startUserName;
    }

    public Long getStartUserId() {
        return startUserId;
    }

    public void setStartUserId(Long startUserId) {
        this.startUserId = startUserId;
    }

    // 任务所有者
    private String owner;

    // 任务负责人
    private String assignee;

    // 父任务id
    private String parentTaskId;

    // 任务的名称
    private String name;

    // 任务的描述（可以为空）
    private String description;

    // 任务的优先级
    private int priority;

    // 任务的创建时间
    private Date createTime;

    // 任务的到期日期（可以为空）
    private Date dueDate;

    // 任务的挂起状态（1表示活动，0表示挂起，但具体值可能因Activiti版本而异）
    private int suspensionState;

    // 任务的类别（可以为空）
    private String category;

    // 与任务关联的执行实例ID
    private String executionId;

    // 流程实例ID
    private String processInstanceId;

    // 流程定义ID
    private String processDefinitionId;

    // 与任务关联的流程定义的任务键
    private String taskDefinitionKey;

    // 与任务关联的表单键（可以为空）
    private String formKey;

    // 是否已删除任务（通常为内部使用）
    private boolean isDeleted;

    // 是否已取消任务（通常为内部使用）
    private boolean isCanceled;

    // 事件名称（如果与特定事件关联，否则可以为空）
    private String eventName;

    // 当前Activiti事件监听器（如果与特定事件关联，否则可以为空）
    // 这里使用Object代替ActivitiListener，因为可能不是所有地方都需要完整的监听器
    private Object currentActivitiListener;


    // 查询变量列表（可以为空）
    private List<VariableInstanceEntity> queryVariables; // 假设这里是一个Object列表，实际类型可能更具体

    // 任务的申领时间（可以为空）
    private Date claimTime;

    // 业务的业务键（可以为空）
    private String businessKey;

    // 应用的版本（可以为空）
    private Integer appVersion;


    // 使用的变量缓存（可以为空）
    private Map<String, VariableInstanceEntity> usedVariablesCache;

    // 缓存的EL上下文（通常为内部使用）
    private Object cachedElContext; // 假设这里是一个Object，实际类型可能更具体

    // 任务的ID
    private String id;

    // 任务的版本（通常为内部使用）
    private int revision;

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getAssignee() {
        return assignee;
    }

    public void setAssignee(String assignee) {
        this.assignee = assignee;
    }

    public String getParentTaskId() {
        return parentTaskId;
    }

    public void setParentTaskId(String parentTaskId) {
        this.parentTaskId = parentTaskId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    public int getSuspensionState() {
        return suspensionState;
    }

    public void setSuspensionState(int suspensionState) {
        this.suspensionState = suspensionState;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getExecutionId() {
        return executionId;
    }

    public void setExecutionId(String executionId) {
        this.executionId = executionId;
    }

    public String getProcessInstanceId() {
        return processInstanceId;
    }

    public void setProcessInstanceId(String processInstanceId) {
        this.processInstanceId = processInstanceId;
    }

    public String getProcessDefinitionId() {
        return processDefinitionId;
    }

    public void setProcessDefinitionId(String processDefinitionId) {
        this.processDefinitionId = processDefinitionId;
    }

    public String getTaskDefinitionKey() {
        return taskDefinitionKey;
    }

    public void setTaskDefinitionKey(String taskDefinitionKey) {
        this.taskDefinitionKey = taskDefinitionKey;
    }

    public String getFormKey() {
        return formKey;
    }

    public void setFormKey(String formKey) {
        this.formKey = formKey;
    }

    public boolean isDeleted() {
        return isDeleted;
    }

    public void setDeleted(boolean deleted) {
        isDeleted = deleted;
    }

    public boolean isCanceled() {
        return isCanceled;
    }

    public void setCanceled(boolean canceled) {
        isCanceled = canceled;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    public Object getCurrentActivitiListener() {
        return currentActivitiListener;
    }

    public void setCurrentActivitiListener(Object currentActivitiListener) {
        this.currentActivitiListener = currentActivitiListener;
    }

    public List<VariableInstanceEntity> getQueryVariables() {
        return queryVariables;
    }

    public void setQueryVariables(List<VariableInstanceEntity> queryVariables) {
        this.queryVariables = queryVariables;
    }

    public Date getClaimTime() {
        return claimTime;
    }

    public void setClaimTime(Date claimTime) {
        this.claimTime = claimTime;
    }

    public String getBusinessKey() {
        return businessKey;
    }

    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }

    public Integer getAppVersion() {
        return appVersion;
    }

    public void setAppVersion(Integer appVersion) {
        this.appVersion = appVersion;
    }


    public Map<String, VariableInstanceEntity> getUsedVariablesCache() {
        return usedVariablesCache;
    }

    public void setUsedVariablesCache(Map<String, VariableInstanceEntity> usedVariablesCache) {
        this.usedVariablesCache = usedVariablesCache;
    }


    public Object getCachedElContext() {
        return cachedElContext;
    }

    public void setCachedElContext(Object cachedElContext) {
        this.cachedElContext = cachedElContext;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getRevision() {
        return revision;
    }

    public void setRevision(int revision) {
        this.revision = revision;
    }

    public static List<ITask> buildByTask(List<Task> tasks){
        List<ITask> res = new ArrayList<>();
        for (Task task : tasks) {
            res.add(buildByTask(task));
        }
        return res;
    }
    public static ITask buildByTask(Task task){
        TaskEntityImpl taskEntity = (TaskEntityImpl)task;
        ITask iTask = new ITask();
        iTask.setOwner(taskEntity.getOwner());
        iTask.setAssignee(taskEntity.getAssignee());
        iTask.setParentTaskId(taskEntity.getParentTaskId());
        iTask.setName(taskEntity.getName());
        iTask.setDescription(taskEntity.getDescription());
        iTask.setPriority(taskEntity.getPriority());
        iTask.setCreateTime(taskEntity.getCreateTime());
        iTask.setDueDate(taskEntity.getDueDate());
        iTask.setSuspensionState(taskEntity.getSuspensionState());
        iTask.setCategory(taskEntity.getCategory());
        iTask.setExecutionId(taskEntity.getExecutionId());
        iTask.setProcessInstanceId(taskEntity.getProcessInstanceId());
        iTask.setProcessDefinitionId(taskEntity.getProcessDefinitionId());
        iTask.setTaskDefinitionKey(taskEntity.getTaskDefinitionKey());
        iTask.setFormKey(taskEntity.getFormKey());
        iTask.setDeleted(taskEntity.isDeleted());
        iTask.setCanceled(taskEntity.isCanceled());
        iTask.setEventName(taskEntity.getEventName());
        iTask.setCurrentActivitiListener(taskEntity.getCurrentActivitiListener());
        iTask.setQueryVariables(taskEntity.getQueryVariables());
        iTask.setClaimTime(taskEntity.getClaimTime());
        iTask.setBusinessKey(taskEntity.getBusinessKey());
        iTask.setAppVersion(taskEntity.getAppVersion());
        iTask.setUsedVariablesCache(taskEntity.getUsedVariablesCache());
        iTask.setCachedElContext(taskEntity.getCachedElContext());
        iTask.setId(taskEntity.getId());
        iTask.setRevision(taskEntity.getRevision());
        return iTask;
    }
}
